<%@ page import="DataBase.DataBase" %>
<%@ page import="BaseClass.UserInfo" %><%--
  Created by IntelliJ IDEA.
  User: 郭宇轩
  Date: 2020/11/17
  Time: 8:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>确认你的地址</title>
    <style type="text/css">
        @import url("../static/css/Header.css");
        @import url("../static/css/BodyPart.css");
    </style>
</head>
<%@ include file="../MainPage/Header.jsp"%>

<% String orderID = request.getParameter("orderID");%>
<% String orderCost = request.getParameter("orderCost");%>
<% String location = session.getAttribute("location").toString(); String name = session.getAttribute("name").toString();%>

<div id="card" class="info1" style="display: block; position: absolute; left: 38.1584%; top: 200px;">
    <a>姓名：</a>
    <input type="text" id="name" value="<%=name %>" onchange="changeUserInfo()">
    <p/>
    <input type="button" onclick="Finished(0)" value="返回">
    <input type="button" onclick="showDiv(2)" value="下一页">
</div>
<div id="card" class="info2" style="display: none; position: absolute; left: 38.1584%; top: 200px;">
    <a>地址：</a>
    <input type="text" id="location" value="<%=location %>" onchange="changeUserInfo()">
    <p></p>
    <form action="../PayOrderServlet?orderID=<%=orderID %>&orderCost=<%=orderCost%>" method="post">
        <input type="button" onclick="showDiv(1)" value="上一页">
        <input type="submit" value="付款">
    </form>
</div>

</form>
</body>
</html>
<script>
    //一键修改
    function changeUserInfo(){
        var nameI = document.getElementById("name");
        var locationI = document.getElementById("location")
        var name = nameI.value;
        var location = locationI.value;
        var xhr = new XMLHttpRequest();

        xhr.onreadystatechange = function () {
            if(xhr.readyState==4 && xhr.status==200){
                locationI.innerText = location;
                nameI.innerText = name;
            }
        }

        xhr.open("POST","${pageContext.request.contextPath}/changeUserInfoServlet?name="+name+"&location="+location+"&confirm="+"1");
        xhr.send(null);
    }

    //显示页码对应的页
    function showDiv(number) {
        for(var i=1;i<=2;i++) {
            var shownDiv = document.getElementsByClassName("info" + i).item(0);

            if(i==number)
                shownDiv.style.display = "block";
            else
                shownDiv.style.display = "none";
        }
    }
    function Finished(number) {
        if(number ==0){//0表示回到上一页
            window.history.back();
        }
        else{//1表示付款

        }
    }
</script>